<?php

class DeletePhoto extends ActionBase {
    public $title = 'Delete photo';

    public function doDelete(){
        if($this->getPhotoService() != null){
            foreach ($_POST['photosId'] as $photoId){
                $photo = $this->photoService->getById($photoId);
                unlink(BASEURL.$photo->original);
                unlink(BASEURL.$photo->mini);
                unlink(BASEURL.$photo->midi);
                unlink(BASEURL.$photo->maxi);
                $this->photoService->delete($photo->id);
            }
        }
    }

    public function DeletePhoto(){

        if($this->getAccount() != null){
            if($_POST['photosId'] != null){
                $this->doDelete();
                $_REQUEST['request']['object'] = 'gallery';
                $_REQUEST['request']['action'] = 'view';
                $_REQUEST['request']['arg'] = $_POST['gallery_id'];
                include_once BASEURL.'action/gallery/wrapper.php';
                new GalleryWrapper();
            }else{
                include_once  BASEURL.'web/layout.php';
            }
        }
    }
}
?>
